package day09API.file;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Demo01 {
    public static void main(String[] args) throws Exception{

        File file = new File("D:\\jsd2107\\File\\demo.txt");
        System.out.println(file.getPath());
        System.out.println(file.length());
        File file1 = new File("./File/demo.txt");
        System.out.println(file1.getPath());
        System.out.println(file1.length());
        System.out.println(file1.exists());
        System.out.println(file1.canRead());//可写
        System.out.println(file1.canWrite());//可写
        System.out.println(file1.lastModified());//最后一次编辑时间
        Date date = new Date(file1.lastModified());
        System.out.println(date.toString());
//        SimpleDateFormat sd = new SimpleDateFormat("yyyy--MM--dd");
//        Date date1 = new Date(sd);
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateString = formatter.format(date);
        System.out.println(dateString);

//创建文件
        File file2 = new File("./File/demo02.txt");
        System.out.println(file2.createNewFile());

//        删除文件
        System.out.println(file2.delete());

        if (! file1.exists()) {
            file1.createNewFile();
            System.out.println("创建了文件");
        }else {
            file1.delete();
            System.out.println("删除了文件");
        }

    }

}
